package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.ResidentTask;
import com.ruoyi.service.IResidentTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 住户核酸任务Controller
 * 
 * @author ruoyi
 * @date 2023-04-10
 */
@RestController
@RequestMapping("/residentTask")
public class ResidentTaskController extends BaseController
{
    @Autowired
    private IResidentTaskService residentTaskService;

    /**
     * 查询住户核酸任务列表
     */
    @RequiresPermissions("residentTask:residentTask:list")
    @GetMapping("/list")
    public TableDataInfo list(ResidentTask residentTask)
    {
        startPage();
        List<ResidentTask> list = residentTaskService.selectResidentTaskList(residentTask);
        return getDataTable(list);
    }

    /**
     * 导出住户核酸任务列表
     */
    @RequiresPermissions("residentTask:residentTask:export")
    @Log(title = "住户核酸任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResidentTask residentTask)
    {
        List<ResidentTask> list = residentTaskService.selectResidentTaskList(residentTask);
        ExcelUtil<ResidentTask> util = new ExcelUtil<ResidentTask>(ResidentTask.class);
        util.exportExcel(response, list, "住户核酸任务数据");
    }

    /**
     * 获取住户核酸任务详细信息
     */
    @RequiresPermissions("residentTask:residentTask:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(residentTaskService.selectResidentTaskById(id));
    }

    /**
     * 新增住户核酸任务
     */
    @RequiresPermissions("residentTask:residentTask:add")
    @Log(title = "住户核酸任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResidentTask residentTask)
    {
        return toAjax(residentTaskService.insertResidentTask(residentTask));
    }

    /**
     * 修改住户核酸任务
     */
    @RequiresPermissions("residentTask:residentTask:edit")
    @Log(title = "住户核酸任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResidentTask residentTask)
    {
        return toAjax(residentTaskService.updateResidentTask(residentTask));
    }

    /**
     * 删除住户核酸任务
     */
    @RequiresPermissions("residentTask:residentTask:remove")
    @Log(title = "住户核酸任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(residentTaskService.deleteResidentTaskByIds(ids));
    }
}
